local nafeng = fk.CreateSkill{
  name = "hanqing__nafeng",
  tags = { Skill.Quest },
}

Fk:loadTranslationTable{
  ["hanqing__nafeng"] = "纳风",
  [":hanqing__nafeng"] = "使命技，中央区移去牌时，若移去的牌数不小于你上次发动，你可以获得中央区的一张牌。<br>\
  ⬤　成功：发动五次〖纳风〗后，你获得一个将“获得”改为“使用”的〖纳风〗；<br>\
  ⬤　失败：五回合未发动〖纳风〗，你删除〖纳风〗的“使命技”标签，然后将“不小于”改为“不大于”。",

  ["#hanqing__nafeng-prey"] = "纳风：你可以获得中央区的一张牌",
  ["#hanqing__nafeng-use"] = "纳风：你可以使用中央区的一张牌",
  ["@hanqing__nafeng"] = "纳风",
}

local DIY = require "packages/diy_utility/diy_utility"

nafeng:addEffect(DIY.BeforeCenterAreaRemove, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(nafeng.name) and
      #player.room:getBanner("@$CenterArea") > 0 and #data.ids >= player:getMark("@hanqing__nafeng")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player, "hanqing__nafeng_fail_count", 0)
    room:setPlayerMark(player, "@hanqing__nafeng", #data.ids)
    local card = room:askToChooseCard(player, {
      target = player,
      flag = { card_data = {{ "@$CenterArea", room:getBanner("@$CenterArea") }} },
      skill_name = nafeng.name,
      prompt = "#hanqing__nafeng-prey",
    })
    room:moveCardTo(card, Card.PlayerHand, player, fk.ReasonJustMove, nafeng.name, nil, true, player)
    if player:usedSkillTimes(nafeng.name, Player.HistoryGame) > 4 and not player.dead and player:hasSkill(nafeng.name, true) then
      room:notifySkillInvoked(player, nafeng.name, "special")
      room:updateQuestSkillState(player, nafeng.name, false)
      room:handleAddLoseSkills(player, "-hanqing__nafeng|hanqing1__nafeng", nil, true, false)
    end
  end,
})

nafeng:addEffect(fk.TurnEnd, {
  late_refresh = true,
  can_refresh = function (self, event, target, player, data)
    return player:hasSkill(nafeng.name, true)
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    if player:usedSkillTimes(nafeng.name, Player.HistoryTurn) > 0 then
      room:setPlayerMark(player, "hanqing__nafeng_fail_count", 0)
    else
      room:addPlayerMark(player, "hanqing__nafeng_fail_count", 1)
    end
  end,
})

nafeng:addEffect(fk.EventTurnChanging, {
  late_refresh = true,
  can_refresh = function (self, event, target, player, data)
    return player:hasSkill(nafeng.name, true)
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    if player:getMark("hanqing__nafeng_fail_count") > 4 then
      room:notifySkillInvoked(player, nafeng.name, "negative")
      room:updateQuestSkillState(player, nafeng.name, true)
      room:handleAddLoseSkills(player, "-hanqing__nafeng|hanqing2__nafeng", nil, true, false)
    end
  end,
})

nafeng:addAcquireEffect(function (self, player, is_start)
  player.room:addSkill("#CenterArea")
end)

return nafeng
